/**
 * 时间膨胀处理
 * 若房间的时间膨胀为1，则表示每间隔1tick会处理一次房间
 */

global.TimeDilation = {

    rooms:{},

    /**
     * 建立一个TimeDilation
     * 由Registry在注册房间时发起调用
     */
    creat:function(roomName,dilation,delay){
        TimeDilation.rooms[roomName] = {
            dilation:dilation,
            delay:delay,
            dilationCountdown:dilation || 0,
            delayContdown:delay || 0,
        }
    },
    
    /**
     * 刷新
     * 由TickStreamLoader在每Tick结束后调用
     * 使所有计时器-1
     */
    flash:function(){
        for(let i in TimeDilation.rooms){
            TimeDilation.rooms[i].dilationCountdown--;
            TimeDilation.rooms[i].delayContdown--;

            if(TimeDilation.rooms[i].dilationCountdown < 0){
                TimeDilation.rooms[i].dilationCountdown = 
                TimeDilation.rooms[i].dilation;
            }
            
        }
    },

    /**
     * 是否处于Dilation，由Intent调用检查
     * 返回true表示处于时间膨胀中，不能执行intent
     */
    isDilation:function(roomName){
        if(TimeDilation.rooms[roomName] == undefined){
            return false;
        }
        if(TimeDilation.rooms[roomName].dilationCountdown <= 0){
            return false;
        }
        return true;
    }

}